package com.fenghuajueli.lib_net;


public class RxUtil {

//    /**
//     * @param activity    Activity
//     * @param showLoading 是否显示Loading
//     * @return 转换后的ObservableTransformer
//     */
//    public static <T> ObservableTransformer<T, T> rxSchedulerHelper(final RxAppCompatActivity activity, final boolean showLoading) {
//        if (activity == null) return rxSchedulerHelper();
//
//        return observable -> {
//            Observable<T> compose = observable.subscribeOn(Schedulers.io())
//                    .observeOn(AndroidSchedulers.mainThread())
//                    .compose(activity.bindUntilEvent(ActivityEvent.DESTROY));
////            if (showLoading) {
////                return compose.compose(ProgressUtils.applyProgressBar(activity));
////            } else {
//                return compose;
//            //}
//        };
//    }


//    /**
//     * @param fragment    fragment
//     * @param showLoading 是否显示Loading
//     * @return 转换后的ObservableTransformer
//     */
//    public static <T> ObservableTransformer<T, T> rxSchedulerHelper(final RxFragment fragment, boolean showLoading) {
//        if (fragment == null || fragment.getActivity() == null) return rxSchedulerHelper();
//        return observable -> {
//            Observable<T> compose = observable.subscribeOn(Schedulers.io())
//                    .observeOn(AndroidSchedulers.mainThread())
//                    .compose(fragment.bindUntilEvent(FragmentEvent.DESTROY));
////            if (showLoading) {
////                return compose.compose(ProgressUtils.applyProgressBar(fragment.getActivity()));
////            } else {
//                return compose;
//            //}
//        };
//    }

//    public static <T> ObservableTransformer<T, T> bindLifeCircle(final Context context,
//                                                                 final ActivityEvent activityEvent) {
//        final ObservableTransformer<T, T> observableTransformer = new ObservableTransformer<T, T>() {
//            @Override
//            public ObservableSource<T> apply(Observable<T> upstream) {
//                if (context instanceof RxAppCompatActivity) {
//                    RxAppCompatActivity fragmentActivity = (RxAppCompatActivity) context;
//                    return (ObservableSource<T>) upstream.subscribeOn(Schedulers.io())
//                            .observeOn(AndroidSchedulers.mainThread())
//                            .compose(fragmentActivity.bindUntilEvent(activityEvent));
//                }
//                return upstream.subscribeOn(Schedulers.io())
//                        .observeOn(AndroidSchedulers.mainThread());
//            }
//        };
//        return observableTransformer;
//    }
//
//    /**
//     * 统一线程处理
//     * @return 转换后的ObservableTransformer
//     */
//    public static <T> ObservableTransformer<T, T> rxSchedulerHelper() {
//        return observable -> observable.subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread());
//    }
}
